package com.midou.administration.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.midou.administration.bo.ClerkBo;
import com.midou.administration.bo.ClerkSelectBo;
import com.midou.administration.entity.Clerk;
import com.midou.administration.mapper.ClerkMapper;
import com.midou.administration.service.ClerkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author MrChen
 * @since 2021-03-24
 */
@Service
public class ClerkServiceImpl implements ClerkService {

    @Autowired
    private ClerkMapper clerkMapper;
    public Clerk login(Clerk clerk){
        QueryWrapper qw = new QueryWrapper();
        qw.eq("clerk_account_number",clerk.getClerkAccountNumber());
        Clerk clerk1 = clerkMapper.selectOne(qw);
        if (clerk1==null){
            throw new RuntimeException("用户不存在");
        }
        if (!clerk1.getClerkPassword().equals(clerk.getClerkPassword())){
            throw new RuntimeException("密码不正确");
        }
        return clerk1;
    }



    public String test(){
        return "ok";
    }

  /* 员工登录 */
  public Clerk doLogin(String name , String pwd){
    return this.clerkMapper.clerkLogin(name, pwd);
  }

    /**
     * 新增员工
     * @param clerk
     * @return
     */
    public int add(Clerk clerk){
        Integer a=clerkMapper.insert(clerk);
        if (a>0){
            return a;
        }else {
            return 0;
        }
    }

    /**
     * 查找所有员工
     */
    public Page all(ClerkBo clerkBo){
        List<ClerkSelectBo> list=clerkMapper.all(clerkBo.getPage(),clerkBo.getBusinessId());
        clerkBo.getPage().setRecords(list);
        return clerkBo.getPage();
    }
    /**
     * 编辑修改员工信息
     */
    public List<ClerkSelectBo> slectId(Integer id){
        return clerkMapper.selectId(id);
    }
    //注册商家员工
    public Integer createClerk(Clerk clerk){
        return clerkMapper.insert(clerk);
    }



    //注册时判断是否有相同的员工和老板账号
    public Clerk selectNumber(String clerkAccountNumber){
        QueryWrapper queryWrapper=new QueryWrapper();
        queryWrapper.eq("clerk_account_number",clerkAccountNumber);
        Clerk clerk=clerkMapper.selectOne(queryWrapper);
        return clerk;
    }


    public int upda(ClerkSelectBo clerkSelectBo){
        int a=clerkMapper.updaClerk(clerkSelectBo);
        return clerkMapper.updaClerk(clerkSelectBo);
    }
    public int delteClerk(Integer id){
        return clerkMapper.deleteById(id);
    }
    /**
     * 修改登录密码
     *
     */
    public int quertupwd(ClerkSelectBo clerkSelectBo){
        return clerkMapper.queryUpwd(clerkSelectBo);
    }
    /**
     * 查看员工账号是否重复
     */
    public List<ClerkSelectBo> chaCf(Clerk clerkSelectBo){
        return clerkMapper.chaCf(clerkSelectBo);
    }
}
